package com.fenghuajueli.module_user.activity.setting;

import android.os.Bundle;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.ToastUtils;
import com.fenghuajueli.libbasecoreui.baseswitch.PublicFunction;
import com.fenghuajueli.libbasecoreui.dialog.CommonTipsDialog;
import com.fenghuajueli.libbasecoreui.feedback.OneFeedbackActivity;
import com.fenghuajueli.libbasecoreui.ui.CustomerServiceActivity;
import com.fenghuajueli.libbasecoreui.utils.JumpActivityUtils;
import com.fenghuajueli.libbasecoreui.viewmodel.BaseViewModel;
import com.fenghuajueli.module_route.UserModuleRoute;
import com.fenghuajueli.module_user.R;
import com.fenghuajueli.module_user.activity.UserViewModelBaseActivity;
import com.fenghuajueli.module_user.databinding.ActivityUserSettingBinding;
import com.fenghuajueli.module_user.model.UserViewModel;


/**
 * 根据设计的情况，我的页面有可能是一个activity，也有个可能是一个activty，跳转activity就用这个
 */
@Route(path = UserModuleRoute.USER_SETTING_ACTIVITY)
public class UserSettingActivity extends UserViewModelBaseActivity implements View.OnClickListener {
    private CommonTipsDialog commonTipsDialog;

    ActivityUserSettingBinding binding;
    private UserViewModel userViewModel = new UserViewModel();

    @Override
    public BaseViewModel setBaseViewModel() {
        return userViewModel;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityUserSettingBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.stVipContainer.setOnClickListener(this);
        binding.stUserFeedBack.setOnClickListener(this);
        binding.stClearCache.setOnClickListener(this);
        binding.stAboutUs.setOnClickListener(this);
        binding.stContactServer.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.stVipContainer) {
            PublicFunction.goComment(this);
        } else if (view.getId() == R.id.stUserFeedBack) {
            JumpActivityUtils.goNormalActivity(this, OneFeedbackActivity.class);
        } else if (view.getId() == R.id.stClearCache) {
            showCommTipDialog();
        } else if (view.getId() == R.id.stAboutUs) {
            JumpActivityUtils.goAboutUsActivity(this);
        } else if (view.getId() == R.id.stContactServer) {
            CustomerServiceActivity.start(this);
        }
    }


    private void showCommTipDialog() {
        hideCommTipDialog();
        commonTipsDialog = new CommonTipsDialog(this, "你确定要清除缓存吗？");
        commonTipsDialog.setCancelListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                hideCommTipDialog();
            }
        });
        commonTipsDialog.setConfirmListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                hideCommTipDialog();
                showLoadingDialog();
                binding.stClearCache.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        hideLoadingDialog();
                        ToastUtils.showShort("清理成功");
                    }
                }, 1500);
            }
        });
        commonTipsDialog.show();
    }

    private void hideCommTipDialog() {
        if (commonTipsDialog != null) {
            commonTipsDialog.dismiss();
            commonTipsDialog = null;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        hideCommTipDialog();
    }
}